using System.Collections.Generic;
using UnityEngine;

namespace Script
{
    public class AudioMgr : MonoBehaviour
    {
        public static AudioMgr Instance;
        public AudioSource AudioSource;
        public List<AudioClip> _audioClips;
        
        private void Awake()
        {
            Instance = this;
        }

        public void PlayLoop(string name,float volum = 1)
        {
            foreach (var audioClip in _audioClips)
            {
                if (audioClip.name == name)
                {
                    AudioSource.clip = audioClip;
                    AudioSource.loop = true;
                    AudioSource.volume = volum;
                    AudioSource.Play();
                }
            }
        }
        
        public void PlayOnce(string name,float volum = 1)
        {
            foreach (var audioClip in _audioClips)
            {
                if (audioClip.name == name)
                {
                    AudioSource.clip = audioClip;
                    AudioSource.loop = false;
                    AudioSource.volume = volum;
                    AudioSource.Play();
                }
            }
        }
        
    }
}